<?php
// +----------------------------------------------------------------------
// | Author: 黄泽宏 <2623213969@qq.com>
// +----------------------------------------------------------------------

namespace app\home\controller;
/**
 * 优惠卷控制器
 */
class CouponController extends HomeController
{
    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 优惠卷列表
     */
    public function index()
    {
        return $this->fetch('index');
    }

    /**
     * 优惠卷 数据 【ajax】
     */
    public function ajax_coupon()
    {
        $status = input('param.status');
        switch ($status) {
            case '1':
                $where = array('uc.user_id' => $this->user_id, 'uc.status' => 1);
                break;
            case '2'://还未支付
                $where = array('uc.user_id' => $this->user_id, 'uc.status' => 2);
                break;
            default:
                break;
        }
        $coupon_list = db('UserCoupon')
            ->alias('uc')
            ->join('__GOODS__ g','g.id = uc.goods_id','LEFT')
            ->field('uc.*,g.goods_name')
            ->where($where)
            ->select();
        $this->ajaxReturn($coupon_list);
    }


}